package controllers;

import java.util.HashMap;
import java.util.List;

import utils.YUtils;

import models.ProjectType;
import models.ProjectVisualize;

public class ProjectTypes extends Application {
	
	public static void index(){
		render();
	}
	
	public static void json(int page,int pagesize) {
		List<ProjectType> projectTypes 
			= ProjectType.all().fetch(page,pagesize);
		HashMap<String, Object> obj = new HashMap<String, Object>();
		obj.put("Rows", projectTypes);
		obj.put("Total", projectTypes.size());
		renderJSON(obj);
	}
	
	public static void add(ProjectType projectType){
		projectType.save();
		ok();
	}
	
	public static void delete(long id){
		ProjectType.findById(id)._delete();
		ok();
	}
	
	public static void loadVisualize(long id){
		List<ProjectVisualize> projectVisualizes
			= ProjectVisualize.find("byProjectType.id", id).fetch();
		String pvListStr = ProjectVisualize.toJSON(projectVisualizes);
		String jsonStr = YUtils.ligerGridData(pvListStr, projectVisualizes.size());
		renderJSON(jsonStr);
	}
	
	public static void addVisualize(ProjectVisualize projectVisualize){
		projectVisualize.save();
		ok();
	}
	
	public static void deleteVisualize(long id){
		ProjectVisualize.findById(id)._delete();
		ok();
	}

}
